/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.krArmor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.hamcrest.Matcher;
import ru.jSky.generator.builder.ruleBuilder.LeveledItemsDistributerToListBuilder;
import ru.jSky.generator.command.Command;
import ru.jSky.interfaces.Armor;
import ru.jSky.interfaces.LeveledItemList;

/**
 *
 * @author Rakev
 */
public class LevelArmorListFillerBuilder {

    private LeveledItemList list;
    private List<KRArmorMatcherBuilder> matcherBuilders = new ArrayList<>();
    private List<Integer> levels = new ArrayList<>();
    private List<Integer> numbers = new ArrayList<>();

    public LevelArmorListFillerBuilder(LeveledItemList list) {
        this.list = list;
    }

    public KRArmorMatcherBuilder createRule() {
        return createRule(1, 1);
    }

    public KRArmorMatcherBuilder createRule(int level) {
        return createRule(level, 1);
    }

    public KRArmorMatcherBuilder createRule(int level, int number) {
        KRArmorMatcherBuilder matcherBuilder = new KRArmorMatcherBuilder();
        matcherBuilders.add(matcherBuilder);
        levels.add(level);
        numbers.add(number);
        return matcherBuilder;
    }

    public Command<Collection<Armor>> build() {
        LeveledItemsDistributerToListBuilder realBuilder = new LeveledItemsDistributerToListBuilder(list);
        for (int i = 0; i < matcherBuilders.size(); i++) {
            Matcher<Armor> ruleMatcher = matcherBuilders.get(i).build();
            int level = levels.get(i);
            int number = numbers.get(i);
            realBuilder.addDistributionRule(ruleMatcher, level, number);

        }
        return realBuilder.build();
    }
}
